﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace WebBanHang
{
    public class User
    {
        string _tenDN, _matKhau;

        public string MatKhau
        {
            get { return _matKhau; }
            set { _matKhau = value; }
        }

        public string TenDN
        {
            get { return _tenDN; }
            set { _tenDN = value; }
        }

        public User(string tenDN, string matKhau)
        {
            _tenDN = tenDN;
            _matKhau = matKhau;
        }

        public bool IsValidLogin()
        {
            string sql = "select * from USERS where TenDN= '" + _tenDN.Replace("'", "'") + "' AND MatKhau= '" + _matKhau.Replace("'", "'") + "'";
            using (DataTable dt = DataProvider.LoadTable(sql))
            {
                bool ret = dt.Rows.Count > 0;
                return ret;
            }
        }

        MyCart _cart;

        public MyCart Cart
        {
            get { return _cart; }
            set { _cart = value; }
        }
        public void InitCart()
        {
            _cart = new MyCart();
        }

        public static User FromId(string tenDN)
        {
            string sql = "select* from USERS where TenDN='" + tenDN.Replace("'", "'") + "'";
            using (DataTable dt = DataProvider.LoadTable(sql))
            {
                DataRow row = dt.Rows[0];
                string matKhau = row["MatKhau"].ToString();
                User ret = new User(tenDN, matKhau);
                return ret;
            }
        }
    }
}